package cn.xxluckey.core;

import java.io.*;
import java.net.*;

public class ChargingPileClient {
    private Socket socket;
    private PrintWriter out;
    private BufferedReader in;

    // 连接充电桩
    public void connect(String address, int port) throws IOException {
        socket = new Socket(address, port);
        out = new PrintWriter(socket.getOutputStream(), true);
        in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    }

    // 发送消息
    public void sendMessage(String message) {
        out.println(message);
    }

    // 接收消息
    public String receiveMessage() throws IOException {
        return in.readLine();
    }

    // 关闭连接
    public void close() throws IOException {
        in.close();
        out.close();
        socket.close();
    }
}
